.PHONY: lint build run wire error

# 定义环境变量
export GOBIN  := $(CURDIR)/bin
# export GIT_GROUP  := $(CURDIR)/bin
# GIT_GROUP := code.snowplus.cn/grpc-server

# error-proto路径
ERROR_DIR     = ./error/
ERROR_PROTO_FILES = $(wildcard $(ERROR_DIR)*.proto)
THIRD_PARTY_DIR = ./third_party

# 代码风格检查
lint:
	@echo ">>> golangci-lint check code....."
	@golangci-lint run

# 单元测试
test:
	@echo ">>> starting unit tests....."
	gotest -v ./... || go test -v ./...

# 清除所有编译生成的文件
clean:
	@echo ">>> clean up......"
ifeq ($(OS),Windows_NT)
	@ del bin/*
else
	@rm -rf bin/*
endif

# 生成可执行文件
build:
	go mod tidy
	@echo ">>> go build......"
	go build -o  $(GOBIN)/grpc-go-server
	go build -o  $(GOBIN)/filler $(CURDIR)/cmd/script/filler

# 运行
run:
	@go run main.go

# wire 依赖注入
wire:
	@echo ">>> wire......"
# cd ./cmd/app && wire
# cd ./cmd/script/index && wire
	cd ./cmd/wire && wire

error:
	@echo ">>> errors......"
	protoc --proto_path=. \
     --proto_path=$(THIRD_PARTY_DIR) \
     --go_out=paths=source_relative:. \
     --go-errors_out=paths=source_relative:. \
     $(ERROR_PROTO_FILES)